package com.cq.hd.app.controller;

import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.utils.IpUtil;
import com.cq.hd.member.api.TbBusinessEnterApplyApi;
import com.cq.hd.member.api.dto.BusinessEnterApplyDto;
import com.cq.hd.member.api.vo.BusinessEnterApplyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/businessEnterApply")
@Api(tags = "商家入驻相关接口")
public class BusinessEnterApplyController {

    @Autowired
    private TbBusinessEnterApplyApi businessEnterApplyApi;

    @ApiOperation(value = "校验邀请码是否有效")
    @ApiResponse(response = Boolean.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/validSettleCode")
    public Result<Boolean> validSettleCode(String settleCode) {
        return businessEnterApplyApi.validSettleCode(settleCode);
    }

    @ApiOperation(value = "商家入驻申请")
    @ApiImplicitParam(name = "businessEnterApplyDto", value = "参数", required = true, paramType = "body", dataType = "BusinessEnterApplyDto")
    @PostMapping("/apply")
    public Result<Boolean> apply(@RequestBody BusinessEnterApplyDto businessEnterApplyDto, @ApiIgnore @LoginUser AppLoginUser appLoginUser, HttpServletRequest request) {
        businessEnterApplyDto.setUserId(appLoginUser.getUserId());
        businessEnterApplyDto.setMobile(appLoginUser.getUserInfo().getMobile());
        businessEnterApplyDto.setApplyIp(IpUtil.getIpAddr(request));
        return businessEnterApplyApi.apply(businessEnterApplyDto);
    }

    @ApiOperation(value = "获取商家入驻信息")
    @ApiResponse(response = BusinessEnterApplyVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getEnterInfo")
    public Result<BusinessEnterApplyVo> getEnterInfo(@ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        return businessEnterApplyApi.getEnterInfoByUserId(appLoginUser.getUserId());
    }

}
